#pragma once

#include "vector2d.h"
#include "drawable.h"
#include "updatable.h"
#include "recievable.h"

// TODO move to the system class
const int K_UP = 'w', K_DN = 's', K_LF = 'a', K_RT = 'd';
const char K_MOVES[] = {K_UP, K_LF, K_DN, K_RT};

class Character : public Drawable, public Updatable, public Recievable
{
protected:
	Vector2D p, preP;
	char icon;
	char color;
public:
	/** empty class as a standard work around for enums */
	class Colors{
	public:
		const static int 
			INVALID = 0,
			Blue = 1,
			Green = 2,
			Cyan = 3,
			Red = 4,
			Magenta = 5,
			Brown = 6,
			LtGray = 7,
			DkGray = 8,
			LtBlue = 9,
			LtGreen = 10,
			LtCyan = 11,
			LtRed = 12,
			LtMagenta = 13,
			Yellow = 14,
			White = 15;
	};
	/** default constructor */
	Character()
		//:p()
	{}
	/**
	 * constructor 
	 * @param color seeCharacter::Colors
	 */
	Character(Vector2D a_p, char a_icon, char color)
		:p(a_p),preP(a_p),icon(a_icon),color(color){}
	/**
	 * reconstructor
	 * @param a_color seeCharacter::Colors
	 */
	void set(Vector2D a_p, char a_icon, char a_color)
	{
		p = a_p;	icon = a_icon;	color = a_color;
	}
	char getIcon(){return icon;}

	Vector2D & getVector2D(){return p;}
	void PrintCharacter()
	{
		HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(hcon,color);
		putchar(icon);
		SetConsoleTextAttribute(hcon,Colors::LtGray);

	}
	void move(char input)
	{
		//save old position
		preP = p;

		//move character
		switch(input)
		{
		case K_UP:	p.y--;	break;
		case K_LF:	p.x--;	break;
		case K_DN:	p.y++;	break;
		case K_RT:	p.x++;	break;
		case ' ':	putchar('\a');	break;
		}
	}
	bool isAt(int x, int y)
	{
		return (y == p.y && x == p.x);
	}
	/** draw the Character */
	void draw()
	{
		COORD origin = {p.x, p.y};
		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), origin);
		PrintCharacter();
	}
	void goBack(){		p = preP;	}

	virtual void Update(float timeElapsed)
	{
	}

	virtual void Recieve(int messageType, void* data)
	{

	}
};
